import fetch from '../../utils/request';

export async function getAllConfigsAxios(userName){//获取当前用户保存的的所有除webapi以外的连接配置
  const params = {
    userName,
  }
  return fetch({
    url: '/api/connectionConfig/getAllConfigs',
    method: 'get',
    params
  });
}

export async function getConfigsAxios(userName,databaseType){//获取当前用户保存指定类型的所有连接
  const params = {
    userName,
    databaseType
  }
  return fetch({
    url: '/api/connectionConfig/getConfigs',
    method: 'get',
    params
  });
}

export async function testConAxios(dataType,params){//测试连接
  let dbType = dataType.toLowerCase();
  return fetch({
    url: `/api/${dbType}/testCon`,
    method: 'get',
    params
  });
}

export async function saveConAxios(dataType,params){//保存连接
  let dbType = dataType.toLowerCase();
  return fetch({
    url: `/api/${dbType}/saveCon`,
    method: 'post',
    params
  });
}

export async function getAllDatabaseAxios(dataType,params){//获取该数据库类型下所有数据库
  let dbType = dataType.toLowerCase();
  return fetch({
    url: `/api/${dbType}/getAllDatabase`,
    method: 'get',
    params
  });
}

export async function getConAxios(dataType,params){//获取指定连接配置
  let dbType = dataType.toLowerCase();
  return fetch({
    url: `/api/${dbType}/getCon`,
    method: 'get',
    params
  });
}

export async function deleteConAxios(dataType,params){//删除连接配置
  let dbType = dataType.toLowerCase();
  return fetch({
    url: `/api/${dbType}/deleteCon`,
    method: 'delete',
    params
  });
}

export async function editConAxios(dataType,params){//编辑连接
  let dbType = dataType.toLowerCase();
  return fetch({
    url: `/api/${dbType}/editCon`,
    method: 'put',
    params
  });
}

export async function getAllTablesAxios(dataType,params){//获取指定数据库下所有表
  let dbType = dataType.toLowerCase();
  return fetch({
    url: `/api/${dbType}/getAllTables`,
    method: 'get',
    params
  });
}

//达梦数据库

// export async function damengGetAllTablesAxios(id){//获取指定数据库下所有表
//   const params = {
//     id
//   }
//   return fetch({
//     url: '/api/dameng/getAllTables',
//     method: 'get',
//     params
//   });
// }

//csv相关配置
export async function updateCsvAxios(configName,description,file,username){//上传要读取的csv文件
  const params = {
    configName,
    description,
    file,
    username
  }
  return fetch({
    url: '/api/csv/uploadFileAndSave',
    method: 'post',
    params
  });
}
//excel
export async function updateExcelAxios(configName,description,file,username){//上传要读取的excel文件
  const params = {
    configName,
    description,
    file,
    username
  }
  return fetch({
    url: '/api/excel/uploadFileAndSave',
    method: 'post',
    params
  });
}
